package com.example.demo.controller;

import com.example.demo.result.ApiResult;
import com.example.demo.service.CollegeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author hongjinhui
 */
@RestController
@RequestMapping("/School/college")
@Api("学院接口")
@Validated
public class CollegeController {
    @Autowired
    private CollegeService collegeService;

    @GetMapping("/list")
    @ApiOperation(value = "查询所有学院名")
    public ApiResult<List<String>> allName() {
        return ApiResult.success(collegeService.getAllCollegeName());
    }

    @GetMapping("/grade/list")
    @ApiOperation(value = "查询某学院的所有年级")
    @ApiImplicitParam(name = "collegeName", value = "学院名", required = true, paramType = "query")
    public ApiResult<List<String>> allGrade(@NotNull(message = "学院名不能为空") String collegeName) {
        return ApiResult.success(collegeService.getAllGradeByCollegeName(collegeName));
    }

    @GetMapping("/class/list")
    @ApiOperation(value = "查询某学院某年级的所有班级")
    @ApiImplicitParams({@ApiImplicitParam(name = "collegeName", value = "学院名", required = true, paramType = "query"),
            @ApiImplicitParam(name = "grade", value = "年级", required = true, paramType = "query")})
    public ApiResult<List<String>> allClass(@NotNull(message = "学院名不能为空") String collegeName,
                                            @NotNull(message = "年级不能为空") String grade) {
        return ApiResult.success(collegeService.getAllClassByCollegeNameAndGrade(collegeName, grade));
    }

}

